package com.yss.system.api.domain;

import java.util.Date;
import java.util.List;
import javax.validation.constraints.*;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yss.common.core.annotation.EasyExcel;
import com.yss.common.core.utils.easyexecl.IntegerConverter;
import com.yss.common.core.utils.easyexecl.StringConverter;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.yss.common.core.web.domain.BaseEntity;
import com.yss.common.core.xss.Xss;

/**
 * 用户对象 sys_user
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("sys_user")
public class SysUser extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 用户ID
     */
    @ExcelIgnore
    @TableId("ID")
    private String id;

    /**
     * 部门ID
     */
    @ExcelIgnore
    @TableField("DEPT_ID")
    private String deptId;

    /**
     * 用户账号
     */
    @ExcelProperty(value = "登录名称")
    @TableField("USER_NAME")
    @Xss(message = "用户账号不能包含脚本字符")
    @NotBlank(message = "用户账号不能为空")
    @Size(min = 0, max = 30, message = "用户账号长度不能超过30个字符")
    private String userName;

    /**
     * 用户昵称
     */
    @ExcelProperty(value = "用户名称")
    @TableField("NICK_NAME")
    @Xss(message = "用户昵称不能包含脚本字符")
    @Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符")
    private String nickName;

    /**
     * 用户邮箱
     */
    @ExcelProperty(value = "用户邮箱")
    @TableField("EMAIL")
    @Email(message = "邮箱格式不正确")
    @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
    private String email;

    /**
     * 手机号码
     */
    @ExcelProperty(value = "手机号码")
    @TableField("PHONENUMBER")
    @Size(min = 0, max = 11, message = "手机号码长度不能超过11个字符")
    private String phonenumber;

    /**
     * 用户性别
     */
    @ExcelProperty(value = "用户性别", converter = StringConverter.class)
    @EasyExcel(readConverterExp = "0=男,1=女,2=未知")
    @TableField("SEX")
    private String sex;

    /**
     * 用户头像
     */
    @ExcelIgnore
    @TableField("AVATAR")
    private String avatar;

    /**
     * 密码
     */
    @ExcelIgnore
    @TableField("PASSWORD")
    private String password;

    /**
     * 帐号状态（0正常 1停用）
     */
    @ExcelProperty(value = "状态", converter = IntegerConverter.class)
    @EasyExcel(readConverterExp = "1=正常,2=停用")
    @TableField("STATUS")
    private Integer status;

    /**
     * 最后登录IP
     */
    @ExcelProperty(value = "最后登录IP")
    @TableField("LOGIN_IP")
    private String loginIp;

    /**
     * 最后登录时间
     */
    @ColumnWidth(30)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ExcelProperty(value = "最后登录时间")
    @TableField("LOGIN_DATE")
    private Date loginDate;

    /**
     * 部门对象
     */
    @ExcelIgnore
    @TableField(exist = false)
    private SysDept dept;

    /**
     * 角色对象
     */
    @ExcelIgnore
    @TableField(exist = false)
    private List<SysRole> roles;

    /**
     * 角色组
     */
    @ExcelIgnore
    @TableField(exist = false)
    private String[] roleIds;

    /**
     * 岗位组
     */
    @ExcelIgnore
    @TableField(exist = false)
    private String[] postIds;

    @ExcelIgnore
    @TableField(exist = false)
    private String roleId;

    public boolean isAdmin() {
        return isAdmin(this.id);
    }

    public static boolean isAdmin(String userId) {
        return "1".equals(userId);
    }


}
